package bankapp.get;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class BankappActivity extends Activity {
    /** Called when the activity is first created. */
	private TodoDbAdapter mDbHelper;
	 private Table table = null;
	 private Long mRowId;
	 private EditText userid;
	    private EditText password,ssid,balance;
	    private Button bt;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        userid = (EditText) findViewById(R.id.etuserid);
        password = (EditText) findViewById(R.id.etpassword);
        ssid = (EditText) findViewById(R.id.etssid);
        balance = (EditText) findViewById(R.id.etbalance);
        bt = (Button) findViewById(R.id.login);
        mDbHelper = new TodoDbAdapter(this);
        mDbHelper.open();
        mRowId = null;
        populateFields();
        bt.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                setResult(RESULT_OK);
                finish();
            }

        });
        System.out.println("task complete11111111111");
        
    }
    
    
    private void populateFields() {

        if (mRowId != null) {
            Cursor todo = mDbHelper.fetchTodo(mRowId);
            startManagingCursor(todo);
            
            userid.setText(todo.getString(todo.getColumnIndexOrThrow(TodoDbAdapter.KEY_USERNAME)));
            password.setText(todo.getString(todo.getColumnIndexOrThrow(TodoDbAdapter.KEY_PASSWORD)));
            ssid.setText(todo.getString(todo.getColumnIndexOrThrow(TodoDbAdapter.KEY_SSID)));
            balance.setText(todo.getString(todo.getColumnIndexOrThrow(TodoDbAdapter.KEY_BALANCE)));
        }
    }
    protected void onSaveInstanceState(Bundle outState) {

        super.onSaveInstanceState(outState);
        saveState();
        outState.putSerializable(TodoDbAdapter.KEY_ROWID, mRowId);
    }

    @Override
    protected void onPause() {

        super.onPause();
        saveState();
    }

    @Override
    protected void onResume() {

        super.onResume();
        populateFields();
    }

    private void saveState() {

    	table = new Table();
    	 //mTodo.category = (String) mCategory.getSelectedItem();
         //mTodo.summary = mTitleText.getText().toString();
         //mTodo.description = mBodyText.getText().toString();
    	table.username = (String)userid.getText().toString();
    	table.password = (String)password.getText().toString();
    	table.ssid=(String)ssid.getText().toString();
    	table.balance=Integer.parseInt((String)balance.getText().toString());
    	System.out.println("enter");
    	
        if (mRowId == null) {
            long id = mDbHelper.createTodo(table);
            if (id > 0) {
                mRowId = id;
            }
        } else {
            mDbHelper.updateTodo(mRowId, table);
        }
    }


}